package com.samoiloff.ui.scroll.resize.view {
	import org.bytearray.display.ScaleBitmap;

	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;

	/**
	 * @author Samoiloff
	 */
	public class SliderView extends EventDispatcher {
		
		private var _mc: Sprite;
		
		private var _sliderNorm	: ScaleBitmap;
		private var _sliderOver	: ScaleBitmap;
		
		public function SliderView(normBitmap:Bitmap, overBitmap:Bitmap) {
			_mc = new Sprite();
			
			_sliderNorm = new ScaleBitmap(normBitmap.bitmapData);
			_sliderOver = new ScaleBitmap(overBitmap.bitmapData);
			
			var r:Rectangle = new Rectangle(1,1,13,2);
			
			_sliderNorm.scale9Grid = r;
			_sliderOver.scale9Grid = r;
			
			_mc.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			_mc.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			_mc.addEventListener(MouseEvent.CLICK, onClick);
			
			_mc.addChild(_sliderNorm);
			_mc.addChild(_sliderOver);
			
			onMouseOut();
		}

		private function onClick(event: MouseEvent): void {
			dispatchEvent(event);
		}

		private function onMouseOver(e:MouseEvent): void {
			_sliderOver.visible = true;
			_sliderNorm.visible = false;
		}

		private function onMouseOut(e:MouseEvent = null): void {
			_sliderOver.visible = false;
			_sliderNorm.visible = true;
		}
		
		public function set height(height:Number):void {
			_sliderNorm.height = height;
			_sliderOver.height = height;
		}
		
		public function get mc(): Sprite {
			return _mc;
		}
	}
}
